//
//  DNStoolManagerTests.m
//  DanoneEA
//
//  Created by Senela on 16/10/31.
//  Copyright © 2016年 翔傲科技. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "DNStoolManager.h"
#import "DNStoolDao.h"

@interface DNStoolManagerTests : XCTestCase
{
    DNStoolModel  *stoolModel;
    DNStoolModel  *stoolModel1;
}
@end

@implementation DNStoolManagerTests

- (void)setUp {
    [super setUp];
    // Put setup code here. This method is called before the invocation of each test method in the class.
    
    stoolModel = [[DNStoolModel alloc] init];
    stoolModel.appId =[NSString stringWithFormat:@"%f", [[NSDate date] timeIntervalSince1970]];
    stoolModel.createTime =[NSString stringWithFormat:@"%.0f", [[NSDate date] timeIntervalSince1970]];
    stoolModel.stoolYn = @"Y";
    stoolModel.stoolCon = [NSNumber numberWithInt:StoolCon_Watery];
    
    
    stoolModel1 = [[DNStoolModel alloc] init];
    stoolModel1.appId =[NSString stringWithFormat:@"%f", [[NSDate date] timeIntervalSince1970]];
    stoolModel1.createTime =[NSString stringWithFormat:@"%.0f", [[NSDate date] timeIntervalSince1970]];
    stoolModel1.stoolYn = @"N";
    stoolModel1.stoolCon = [NSNumber numberWithInt:StoolCon_Soft];
}

- (void)tearDown {
    // Put teardown code here. This method is called after the invocation of each test method in the class.
    [super tearDown];
}

- (void)testExample {
    // This is an example of a functional test case.
    // Use XCTAssert and related functions to verify your tests produce the correct results.
}

- (void)testPerformanceExample {
    // This is an example of a performance test case.
    [self measureBlock:^{
        // Put the code you want to measure the time of here.
    }];
}


-(void)test1AddSuc
{
    // 场景一： 成功－ 新增stool diary
    BOOL ret = [[DNStoolManager sharedInstance] addDiary:stoolModel];
    XCTAssertEqual(ret, YES, @"add Stool Diary failed!");
  
}



-(void)test2ModifySuc
{
    // 场景二： 成功－ 编辑stool diary
    stoolModel.stoolYn = @"N";
    stoolModel.modifyReason = @"Don't remember";
    BOOL ret = [[DNStoolManager sharedInstance] modifyDiary:stoolModel];
    XCTAssertEqual(ret, YES, @"modify Stool Diary failed!");
    
}


-(void)test3DeleteSuc
{
    // 场景三： 成功－ 删除stool diary
    stoolModel.deleteReason = @"delete reason";
    BOOL ret = [[DNStoolManager sharedInstance] deleteDiary:stoolModel];
    XCTAssertEqual(ret, YES, @"delete Stool Diary failed!");
}


-(void)test4SaveArr
{
    [[DNDataBase shareInstance] clearAllTableData];
    
    NSMutableArray *stoolArr = [NSMutableArray array];
    NSTimeInterval timeInterval =  [[NSDate date] timeIntervalSince1970];
    for(int i=0; i<60; i++)
    {
        DNStoolModel  *stoolTempModel = [[DNStoolModel alloc] init];
        stoolTempModel.stoolYn = @"Y";
        stoolTempModel.stoolCon = [NSNumber numberWithInt:StoolCon_Watery];
        //CHG Jery 2016-11-02  修改创建时间超出当前时间的问题
        stoolTempModel.appId =[NSString stringWithFormat:@"%.0f", timeInterval - i];
        stoolTempModel.createTime =[NSString stringWithFormat:@"%.0f", timeInterval - i];
        stoolTempModel.status = [NSNumber numberWithInt:OPStatus_ADD];
        
        [stoolArr addObject:stoolTempModel];
    }
    
    BOOL ret =[[DNStoolManager sharedInstance] saveStoolDairyArrToLocalDB:stoolArr];
    XCTAssertEqual(ret, YES, @"DNStoolManager-- saveStoolDairyArrToLocalDB error");
    
    NSMutableArray *displayArr = [[[DNStoolDao alloc] init] getAppDisplayObjectModel];
    XCTAssertEqual(displayArr.count, 60, @"DNStoolManager-- getAppDisplayObjectModel error");
}

@end
